package com.example.test2application;

import java.util.List;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.app.Activity;
import android.content.Intent;

public class MainActivity extends Activity {

	protected CustomApplication app;
	
	public ListView mainListView;
	
	protected List<EventModel> events;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
	    // Get the application instance
		app = (CustomApplication)getApplication();
		events = app.getEvents();
		mainListView = (ListView) findViewById(R.id.mainListView);
		mainListView.setAdapter(new CustomArrayAdapter(this, events));
		
		mainListView.setOnItemClickListener(sendListener);
    }

    private OnItemClickListener sendListener = new OnItemClickListener() {
		
    	@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			/*
			 * Toast.makeText(getApplicationContext(), "Click ListItem " +
			 * values[position], Toast.LENGTH_LONG) .show();
			 */
    		EventModel event = events.get(position);
    		app.setEvent(event);
			
    		Intent intent = new Intent(MainActivity.this, EventActivity.class);
			startActivity(intent);
		}
    	
	};
}
